<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ClassesRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $routeAs = $this->route()->action['as'];
        $rules = [];

        switch ($routeAs) {
            case 'classes.index':
                $rules = [
                    'academic_year' => 'nullable|integer',
                ];
                break;
            case 'classes.create':
            case 'classes.update':
                $rules = [
                    'academic_year' => 'required|integer',
                ];
                break;
        }

        return $rules;
    }

    public function attributes()
    {
        return [
            'academic_year' => '学年',
        ];
    }
}
